package Java.BlackHorse.Stream;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.function.Consumer;
import java.util.function.IntFunction;

public class StreamDemo8 {
    /*
    stream流的终结方法
    * 遍历
    * 统计
    * 收集流中的数据，放到数组中
    * */

    public static void main(String[] args) {
        ArrayList<String> list = new ArrayList<>();
        Collections.addAll(list,"张三","李四","王五","沈六");

        //void forEach(Consumer action) 遍历
       /*
        list.stream().forEach(new Consumer<String>() {
            @Override
            public void accept(String s) {
                System.out.println(s);
            }
        });
        */
        System.out.println("----------遍历----------");
        list.stream().forEach(s -> System.out.println(s));

        System.out.println("----------统计----------");
        long len = list.stream().count();
        System.out.println(len);

        System.out.println("---------收集流中的数据，放到数组中-----------");
        Object[] arr = list.stream().toArray();
        System.out.println(Arrays.toString(arr));

//       String[] arr1 = list.stream().toArray(new IntFunction<String[]>() {
//            @Override
//            public String[] apply(int value) {
//               return new String[value];
//            }
//        });
        String[] arr1 = list.stream().toArray(value -> new String[value]);
        System.out.println(Arrays.toString(arr1));


    }
}
